package router

import (
	"ims/app/api"
	"ims/app/service"
	"ims/app/tmpl"
	"ims/app/webapi"
	"ims/app/ws"

	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
)

func init() {
	s := g.Server()

	s.Group("/", func(group *ghttp.RouterGroup) {
		//加入jwt token鉴权，下面接口都先经过此中间件
		group = group.Middleware(service.JWTauthMiddewareAuth)
		group.ALL("/check_auth", api.CheckAuth)
		group.GET("/ws_kefu", ws.NewKefuServer)
		group.GET("/visitors_kefu_online", api.GetKefusVisitorsOnline)
		group.GET("/visitors", api.GetVisitors)
		group.GET("/visitor", api.GetVisitor)
		group.GET("/other_kefulist", api.OtherKefulist)
		group.GET("/trans_kefu", api.GetTransKefu)
		//下面接口 增加此中间件
		// 请求进入 JWTauthMiddewareAuth 、MiddlewareRbacAuth、再到/kefuinfo
		group.Middleware(service.MiddlewareRbacAuth)
		group.GET("/kefuinfo", api.Kefuinfo)
	})
	//消息接口
	s.Group("/2", func(group *ghttp.RouterGroup) {
		group.POST("/message", api.SendMessage)

		group.GET("message_close", api.SendCloseMessageV2)

	})

	s.Group("/", func(group *ghttp.RouterGroup) {
		group.GET("/", tmpl.PageIndex)
		group.GET("/index", tmpl.PageIndex)
		group.GET("/messages", api.GetVisitorMessage)
		group.POST("/message", api.SendMessage)
		//ws
		group.GET("/chat_server", api.NewChatServer)
		//通过http的upgrade升级到ws接口
		group.GET("/ws", ws.PageNewChatServer)

		group.ALLMap(g.Map{
			"/login":     tmpl.PageLogin,
			"/main":      tmpl.PageMain,
			"/chat_main": tmpl.PageChatMain,
			"/check":     api.LoginCheckPass,
		})

		//前台访客聊天
		group.GET("/chat_page", tmpl.PageChat)
		group.GET("/chatIndex", tmpl.PageChat)
		group.GET("/notice", api.GetNotice)
		group.POST("/visitor_login", api.PostVisitorLogin)

	})
	//客服聊天界面获取 和某个客户的聊天列表
	s.Group("/api", func(group *ghttp.RouterGroup) {
		group = group.Middleware(service.MiddlewareCORS)

		//kefu聊天ui界面 的接口
		group.Group("/kefu", func(group *ghttp.RouterGroup) {
			group.POST("/login", webapi.Kefu.Login)
			group.ALL("/service/list", webapi.Service.GetChatList)

			group.Middleware(service.KefuAuthTokenMiddleware)
			group.GET("/service/info", webapi.Service.GetServiceInfo)
			group.GET("/user/record", webapi.Kefu.GetKefuRecordList)
		})

		//用户界面ui上的接口
		group.Group("/mobile", func(group *ghttp.RouterGroup) {
			group.Middleware(service.MiddlewareUserToken)
			group.GET("/user/record", webapi.User.GetRecordList)

			group.ALL("service/upload", webapi.User.Upload)
		})

	})
}
